package database;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author tamara
 */
public class DatabaseConnection {

    private Connection con;

    public void connect() {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //load the JDBC-ODBC driver
            String url = "jdbc:odbc:Driver={Microsoft Access Driver " + "(*.mdb, *.accdb)};DBQ=D:\\CocktailPlanner.accdb";
            //declare a variable which store a string of the driver name for Microsoft Access 2007 and the location of the Northwind database
            con = DriverManager.getConnection(url);
            System.out.println("Connected!");

        } catch (Exception ex) {
            Logger.getLogger(DatabaseConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void disconnect() {
        try {
            con.close();
            System.out.println("Disconnected!");
        } catch (SQLException ex) {
            Logger.getLogger(DatabaseConnection.class.getName()).log(Level.SEVERE, ex.getMessage());
        }
    }

    public Connection getCon() {
        return con;
    }
}